<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;
use common\models\business\BusinessCustomerCategory;
use yii\helpers\ArrayHelper;
/* @var $this yii\web\View */
/* @var $model common\models\business\BusinessCustomer */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="row">
    <div class="col-lg-12">
        <section class="panel">
        <div class="panel-body">
            <div class="adv-table editable-table ">
                <div class="business-customer-form">
                    <?php $form = ActiveForm::begin([
                        'options' => ['class' => 'form-horizontal','enctype' => 'multipart/form-data'],
                        'fieldConfig' => [
                            'template' => "<div class='col-xs-3 col-sm-2 text-right'>{label}</div><div class='col-xs-9 col-sm-7'>{input}</div><div class='col-xs-12 col-xs-offset-3 col-sm-3 col-sm-offset-0'>{error}</div>",
                        ]
                    ]); ?>

                        <?= $form->field($model, 'number')->textInput(['maxlength' => true,'value'=>!empty($model->number)?$model->number:date('YmdH').rand(100,999),'readonly'=>true]) ?>

                        <?= $form->field($model, 'cateid')->dropDownList(ArrayHelper::map(BusinessCustomerCategory::allCate(),'id','name')) ?>

                        <?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>

                        <?= $form->field($model, 'personA')->textInput(['maxlength' => true]) ?>

                        <?= $form->field($model, 'personB')->textInput(['maxlength' => true]) ?>

                        <?= $form->field($model, 'connect_tel')->textInput(['maxlength' => true]) ?>

                        <?= $form->field($model, 'connect_address')->textInput(['maxlength' => true]) ?>

                        <?= $form->field($model, 'status')->dropDownList(\common\models\business\BusinessCustomer::$statues) ?>


                        <!--附加字段-->
                        <?php if($model->addonField) { ?>
                            <?php foreach($model->addonField as $key => $row) { ?>
                                <div class="form-group field-businesscontract-"<?= $row->name?>>
                                    <div class="col-xs-3 col-sm-2 text-right"><label class="control-label" for="businesscontract-"<?= $row->name?>><?= $row->name?></label></div><div class="col-xs-9 col-sm-7"><input type="text" id="businesscontract-"<?= $row->name?> class="form-control" name="<?= $row->name?>" value="<?= \common\models\business\BusinessCustomer::fieldValue($model->id,$row->id)?>" aria-required="true" aria-invalid="false"></div><div class="col-xs-12 col-xs-offset-3 col-sm-3 col-sm-offset-0"><div class="help-block"></div></div>
                                </div>
                            <?php } ?>
                        <?php } ?>


                    <div class="form-group">
                        <?= Html::submitButton($model->isNewRecord ? '确认提交' : '确认更新', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
                    </div>
                    <?php ActiveForm::end(); ?>
                </div>
            </div>
        </div>
    </section>
</div>
</div>



<script>
    <?php $this->beginBlock('js_end') ?>

    $('#businesscustomer-cateid').change(function () {
        var url = '<?= Yii::$app->request->pathInfo ?>';
        <?php if($model->isNewRecord) { ?>
            window.location.href = '/'+url+'?cateid='+$(this).val();
        <?php } ?>

    });

    <?php $this->endBlock(); ?>
    <?php $this->registerJs($this->blocks['js_end'],\yii\web\View::POS_END);//将编写的js代码注册到页面底部 ?>
</script>
